//
// Created by apple on 2021/12/22.
//

#ifndef PUSHER_VIDEOCHANNEL_H
#define PUSHER_VIDEOCHANNEL_H
#include <pthread.h>
#include "librtmp/rtmp.h"

#include "include/x264.h"

class VideoChannel {
    typedef void (*VideoCallback)(RTMPPacket* packet);

public:
    VideoChannel();

    ~VideoChannel();

    //创建x264编码器
    void setVideoEncInfo(int width, int height, int fps, int bitrate);
    //函数指针主要用于回调带外层
    void setVideoCallback(VideoCallback callback);
    void encodeData(int8_t *data);
private:
    int mWidth;
    int mHeight;
    int mFps;
    int mBitrate;
    VideoCallback callback;
    pthread_mutex_t mutex;
    int index = 0;
    int ySize;
    int uvSize;
    x264_t *videoCodec = 0;
    //图片
    x264_picture_t *pic_in = 0;
    //发送数据

    void sendSpsPps(uint8_t *sps, uint8_t *pps, int len, int pps_len);
    void sendFrame(int type, int payload, uint8_t *p_payload);

};


#endif //PUSHER_VIDEOCHANNEL_H
